<?php
class IndexAction extends CommonAction {

	// 框架首页
	public function index() {
		if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {
			//显示菜单项
			$menu = array ();
			if(isset($_SESSION['menu'.$_SESSION[C('USER_AUTH_KEY')]])) {

                //如果已经缓存，直接读取缓存
                $menu   =   $_SESSION['menu'.$_SESSION[C('USER_AUTH_KEY')]];
            }else {
				//读取数据库模块列表生成菜单项
				$node = M ( "Node" );
				$id = $node->getField ( "id" );
				$pwhere['level'] = 1;
				$pwhere['status'] = 1;
				$plist = $node->where($pwhere)->field('id,name,group_id,pid,title')->order('sort asc')->select();
				foreach($plist as $k=>$v){
					$where ['status'] = 1;
					$where ['pid'] = $v['id'];
		            //$where ['level'] = 2;
		            $where ['_string'] = 'level=2';
					$list[$k] = $node->where ( $where )->field ( 'id,name,pid,title,level' )->order ( 'level, sort asc' )->select ();				
				}
				$accessList = $_SESSION ['_ACCESS_LIST'];
				//print_r($accessList);
				foreach ( $list as $key => $kv ) {
					if(!empty($kv) && is_array($kv)){
						foreach ($kv as $ck=>$module){
							if (isset ( $accessList [strtoupper($plist[$key]['name']) ] [strtoupper ( $module ['name'] )] ) || $_SESSION ['administrator']) {
								//设置模块访问权限
								$module ['access'] = 1;
								$menu [$key][$ck] = $module;
								$menu [$key]['name'] = $plist[$key]['title'];
							}
						}					
					}
				}
				if (! empty ( $_GET ['tag'] )) {
					$this->assign ( 'menuTag', $_GET ['tag'] );
				}
				//dump($menu);
				$this->assign ( 'menu', $menu );
            }
		}
		C ( 'SHOW_RUN_TIME', false ); // 运行时间显示
		C ( 'SHOW_PAGE_TRACE', false );
		$this->display ();
	}

}
?>